package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.PackageCoin;
import com.api.user.service.PackageCoinService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/04/08.
*/
@PowerEnable(name = "充值套餐",url = "/package/coin")
@Api(value = "充值套餐", tags = {"充值套餐"})
@RestController
@RequestMapping("/package/coin")
public class PackageCoinController extends Ctrl{
    @Resource
    private PackageCoinService packageCoinService;

    @ApiOperation(value = "充值套餐添加", tags = {"充值套餐"}, notes = "充值套餐添加")
    @PostMapping(value="/add",name="充值套餐添加")
    public Result add(@ApiParam PackageCoin packageCoin) {
        if(packageCoin.getId()!=null){
            packageCoinService.update(packageCoin);
        }else {
            packageCoinService.save(packageCoin);
        }
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "充值套餐删除", tags = {"充值套餐"}, notes = "充值套餐删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "充值套餐id", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="充值套餐删除")
    public Result delete(@RequestParam Long id) {
        PackageCoin coin = packageCoinService.findById(id);
        coin.setDisabled(false);
        packageCoinService.update(coin);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "充值套餐详细信息", tags = {"充值套餐"}, notes = "充值套餐详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "充值套餐id", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/detail",name="充值套餐详细信息")
    public Result detail(@RequestParam Integer id) {
        PackageCoin packageCoin = packageCoinService.findById(id);
        return ResultGenerator.genSuccessResult(packageCoin);
    }

    @ApiOperation(value = "充值套餐列表信息", tags = {"充值套餐"}, notes = "充值套餐列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list", name = "充值套餐列表信息")
    public Result list(@RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size) {
        return packageCoinService.list(page, size);
    }
}
